#!/bin/bash

current_time=`adb shell date "+%y_%m_%d_%H_%M_%S"`
mkdir $current_time
exec 1>./$current_time/cpu_gpu_info_$current_time.csv

echo -e "\n----check cpu/gpu----"
echo "time,foreground_cpu,top_cpu,background_cpu,cpu_index,cpu_max_freq,cpu_min_freq,cpu_current_freq,cpu_available_freqs,gpu_clock,gpu_max_clock,gpu_busy"
isToRunning=true
trap "isToRunning=false" SIGINT

while $isToRunning
do
	nowtime=`adb shell date "+%y_%m_%d_%H_%M_%S"`
	fgcpu=`adb shell cat /dev/cpuset/foreground/cpus`
	topcpu=`adb shell cat /dev/cpuset/top-app/cpus`
	bgcpu=`adb shell cat /dev/cpuset/background/cpus`
	gpuclk=`adb shell cat /sys/class/kgsl/kgsl-3d0/gpuclk`
	gpumaxclk=`adb shell cat /sys/class/kgsl/kgsl-3d0/max_gpuclk`
	gpubusy=`adb shell cat /sys/class/kgsl/kgsl-3d0/gpubusy`
	
	#echo "cpu schedule info,foreground cpu, top cpu, background cpu,cpu index,cpu max freq, cpu min freq, cpu current freq, cpu available freqs, gpu info, gpu clock, gpu max clock, gpu busy"
	for i in {0..7}
	do
		cpumaxfreq=`adb shell cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_max_freq`
		cpuminfreq=`adb shell cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_min_freq`
		cpucurfreq=`adb shell cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_cur_freq`
		cpu_av_freq=`adb shell cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_available_frequencies`
		echo "$nowtime,$fgcpu,$topcpu,$bgcpu,cpu${i},$cpumaxfreq,$cpuminfreq,$cpucurfreq,$cpu_av_freq$gpuclk,$gpuclk,$gpumaxclk,$gpubusy"
	done
done
